package io.adrainty.algorithm.leetcode.lcr;

/**
 * LCR 008. 长度最小的子数组
 * @link <a href="https://leetcode.cn/problems/2VG8Kg/">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/9/8 下午7:52
 */
public class LCR009 {

    public int numSubarrayProductLessThanK(int[] nums, int target) {
        int ans = 0;
        int left = 0;
        int right = 0;
        int sum = 1;
        while (right < nums.length) {
            sum *= nums[right];
            while (left <= right && sum >= target) {
                sum /= nums[left++];
            }
            ans += right >= left? right - left + 1: 0;
            right++;
        }
        return ans;
    }

}
